DESCRIPTION

We are installing the ‘openai’ for r package and setting up the API key so that you can interact with openai engines while in foreign IDE (RStudio). There is also a package called ‘gptstudio’ for addins that connect with the OpenAi engines directly in RStudio and we will check that out later.

Before or After you install the packages you must create an account with OpenAi so you can receive a personal API Key and access the gpt engines. Link: OpenAi-Account-Registration

SET UP

## install.packages("openai")
## install.packages("gptstudio")

## set up environment

library(tidyverse)
library(openai)
library(gptstudio)

‘openai’ package use: API key authentication-global set up

Credit this portion to github user: irudnyts, who develops packages for R

‘openai’ package examples

NOTE: Anything you send as an API request to OpenAi is being shared with them, Remember to keep prompts away from containing PII, sensitive information, etc.

Below, you can see the ai generated text to image after pasting the output URL in a browser and making sure the image is the one we want and the prompt does not need to be changed. From the URL I saved the image file and then linked it here and I will do the same with the second example.

NOTE: I did try just inserting the URL but the authentication token that uses my API key was timing out after a certain amount of time so I just saved the image file from the URL and inserted the file that way instead of just a URL.

## run this code in the console and it will return a url with the result of your query.

create_image("An astronaut-horse eating pizza on the beach")

ai-generated-text-to-image-“An astronaut-horse eating pizza on the beach”

## run this code in the console and it will return a url with the result of your query.
## you can change the prompt and request another query if the image is not what you want.

create_image("The Yorkie dog pirate, Captain Dog, eating a sushi roll with chopsticks")

ai-generated-text-to-image-“The Yorkie dog pirate, Captain Dog, eating a sushi roll with chopsticks”

‘gptstudio’ package use: Addins>ChatGpt

Credit this portion to github user: MichelNivard, who develops packages for R